package cn.chia.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.chia.back.dao.IActivityDAO;
import cn.chia.back.dao.IActivityTypeDAO;
import cn.chia.front.dao.IItemDAO;
import cn.chia.pojo.TblActivity;
import cn.chia.pojo.TblActivityType;
import cn.chia.pojo.TblItems;
import cn.chia.service.IActivityService;

@Service
public class ActivityServiceImpl implements IActivityService {
	
	private IActivityDAO activityDAOImpl;
	private IActivityTypeDAO activityTypeDAOImpl; 
	private IItemDAO itemDAOImpl;
	
	/**
	 * @author Administrator
	 * @param activity 
	 * @Todo 添加活动
	 */
	public void addActivity(TblActivity activity) throws Exception {
		activityDAOImpl.doCreate(activity);
	}

	/**
	 * @author Administrator
	 * @param pageNo
	 * @param pageSize
	 * @param keyword
	 * @param column
	 * @return map
	 * @将dao层的getAllCount()方法和findAll()方法的返回值分别封装成map集合并将map集合返回。
	 * @throws Exception
	 */
	public Map<?, ?> findAllActivity(int pageNo, int pageSize, String keyword,
			String column) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("allActivity", activityDAOImpl.findAll(pageNo,pageSize, keyword, column));
		map.put("allActivityCount", activityDAOImpl.getAllCount(keyword, column));
		return map;
	}


	/**
	 * @author Administrator
	 * @param activityId
	 * @return Activity实体类
	 * @Todo 按照id查询某一条记录。
	 * @throws Exception
	 */
	public TblActivity getActivityById(Integer activityId) throws Exception {
		return activityDAOImpl.findById(activityId);
	}

	
	/**
	 * @author Administrator
	 * @param activity
	 * @Todo 修改原有活动
	 * @throws Exception
	 */
	public void modifyActivity(TblActivity activity) throws Exception {
		activityDAOImpl.doUpdate(activity);
	}

	
	/**
	 * @author Administrator
	 * @param activityId 
	 * @Todo 删除原有的活动。
	 * @throws Exception
	 */
	public void removeActivity(Integer activityId) throws Exception {
		activityDAOImpl.doRemove(activityId);
	}

	/**
	 * @author Administrator
	 * @Todo 查询活动的全部种类
	 * @return 活动种类的list集合
	 * @throws Exception
	 */
	public List<TblActivityType> findAllActivityType() throws Exception {
		return activityTypeDAOImpl.findActivityType();
	}
	
	/**
	 * @Todo 修改商品的活动情况
	 */
	public void modifyActivityInItems(String itemId,Integer activityId) throws Exception{
		itemDAOImpl.updateItemsActivity(itemId, activityId);
	}
	//通过ID找活动
	public TblActivity findById(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return activityDAOImpl.findById(id);
	}
	
	
	@Resource(name="activityDAOImpl")
	public void setActivityDAOImpl(IActivityDAO activityDAOImpl) {
		this.activityDAOImpl = activityDAOImpl;
	}

	@Resource(name="activityTypeDAOImpl")
	public void setActivityTypeDAOImpl(IActivityTypeDAO activityTypeDAOImpl) {
		this.activityTypeDAOImpl = activityTypeDAOImpl;
	}

	@Resource(name="itemDAOImpl")
	public void setItemDAOImpl(IItemDAO itemDAOImpl) {
		this.itemDAOImpl = itemDAOImpl;
	}

	
}
